package netty.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by yu756 on 2020/1/9 16:51
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageProtocol msg, ByteBuf byteBuf) throws Exception {
        System.out.println("MyMessageEncoder encode 被调用");

        byteBuf.writeInt(msg.getLen());
        byteBuf.writeBytes(msg.getContent());

    }
}
